package org.dromara.common.feign.config;

import feign.Logger;
import org.dromara.common.core.factory.YmlPropertySourceFactory;
import org.dromara.common.feign.interceptor.FeignInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

/**
 * @description:
 * @author: zhou shuai
 * @date: 2024/2/21 15:38
 * @version: v1
 */
@AutoConfiguration
@EnableFeignClients("org.dromara.*.api.feign")
@ComponentScan({"org.dromara.*.api.feign.fallback", "org.dromara.*.api.services"})
@PropertySource(value = "classpath:common-feign.yml", factory = YmlPropertySourceFactory.class)
public class FeignConfig {

    @Bean
    @Primary
    public Logger.Level feignLogLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    @ConditionalOnProperty(name = "feign.log.enabled", havingValue = "true", matchIfMissing = true)
    public MyFeignLogger myFeignLogger() {
        return new MyFeignLogger();
    }

    @Bean
    public FeignInterceptor feignInterceptor() {
        return new FeignInterceptor();
    }

}
